﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Home.MobileSales.Common.Entities;

namespace Home.MobileSales.ImpExpData.Core
{
    public abstract class ExportVisits : ExportData
    {
        protected List<Visit> visits;
        protected XmlWriter xml;

        virtual protected void ExportVisit()
        {
            
            foreach (var visit in visits)
            {
                xml.WriteStartElement("Visit");
                xml.WriteStartAttribute("Date");
                xml.WriteValue(visit.DateVisit);
                xml.WriteStartAttribute("IdBuyPoint");
                xml.WriteValue(visit.BuyPoint.IdBuyPoint);
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("TimeEndVisist");
                xml.WriteValue(visit.TimeEndVisit ?? string.Empty);
                xml.WriteEndAttribute();
                xml.WriteStartAttribute("GpsPosition");
                xml.WriteValue(visit.GpsPosition ?? string.Empty);
                xml.WriteEndAttribute();
                foreach (var order in visit.Orders)
                {
                    xml.WriteStartElement("Order");
                    xml.WriteStartAttribute("Date");
                    xml.WriteValue(order.DateOrder);
                    xml.WriteEndAttribute();
                    xml.WriteStartAttribute("Number");
                    xml.WriteValue(order.NumberOrder);
                    xml.WriteEndAttribute();
                    xml.WriteStartAttribute("Sklad");
                    xml.WriteValue(order.SkladId);
                    xml.WriteEndAttribute();
                    foreach (var recordOrder in order.RecordOrders)
                    {
                        xml.WriteStartElement("RecordOrder");
                        xml.WriteStartAttribute("IdGood");
                        xml.WriteValue(recordOrder.Good.idGood);
                        xml.WriteEndAttribute();
                        xml.WriteStartAttribute("Price");
                        xml.WriteValue(recordOrder.Price);
                        xml.WriteEndAttribute();
                        xml.WriteStartAttribute("Quantity");
                        xml.WriteValue(recordOrder.Quantity);
                        xml.WriteEndAttribute();
                        xml.WriteEndElement();
                    }
                    xml.WriteEndElement();
                }
                xml.WriteEndElement();
            }
            //xml.WriteEndDocument();
        }


    }
}

